# 元组 只读不写
t1 = (1, 2, False, "name")
t2 = ()
t3 = tuple()
print(type(t1), t1)
print(type(t2), t2)
print(type(t3), t3)

# 单个元素如果要成为列表的话,需要补上','
t1 = ("hello")  # 该定义不是元组，是字符串
t2 = ("haha", )
print(type(t1), t1)
print(type(t2), t2)

# 获取下标
print(t1.index("hello"))

# 获取长度
print(len(t1))  # 字符串长度
print(len(t2))  # 元组长度

# 获取某个元素的个数
t1 = (1, 1, 2, 5, 6, 2, 4, 2)
print(t1.count(2))

# 遍历
for t in t1:
    print(t, end=' ')

print()

# 元组内嵌套列表 则列表的内容可以改变 (列表的地址没有变)
t2 = (1, "haha", [2, 3, "hi"], 88)
print(t2)
t2[2][1] = 8
print(t2)
t2[2].append("new")
print(t2)
t2[2].pop(0)
print(t2)
del t2[2][-1]
print(t2)
